<?php

Raise::load('core.RaiseTempalte');

/**
 * TestCoreRaiseTemplate class
 * Testing unit of 'phpraise/core/RaiseTemplate.php'
 *
 * @author Sam-Mauris Yong <hellclanner at live dot com>
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @package Raise.UnitTest.Test
 */
class TestCoreRaiseTemplate extends RaiseTest {

    public static function testClass() {
        self::assertClassExists('RaiseTemplate');
        self::assertClassMethod('RaiseTemplate', 'loadTemplate');
        self::assertClassMethod('RaiseTemplate', 'loadCount');
        self::assertClassMethod('RaiseTemplate', 'fields');
        self::assertClassMethod('RaiseTemplate', 'parse');
        self::assertClassMethod('RaiseTemplate', 'tokens');
        self::assertClassExtends('RaiseTemplate', 'RaiseObject');
    }

    public static function testTemplate(){
        RaiseTemplate::loadTemplate(new RaiseFile('mocks/raise/template/template.html'));
        $t = new RaiseTemplate('template');
        self::assertStrictEqual(RaiseTemplate::loadCount(), 1);
        self::assertObjectClass($t, 'RaiseTemplate');
        $t->fields()->add('page.doctype', '');
        $t->fields()->add('page.title', 'PageTitle');
        $t->fields()->add('default', 'valid');
        self::assertType($t->parse(), 'string');
        $dom = RaiseDomParser::parseString($t->parse());
        self::assertStrictEqual($dom->select('title')->children()->get(0)->tag()->value(), 'PageTitle');
        self::assertStrictEqual(trim($dom->select('body')->children()->get(0)->tag()->value()), 'valid');
        self::assertStrictEqual($t->tokens()->toArray(), array('page.doctype', 'page.title', 'default'));
        self::assertStrictEqual($t->tokens()->count(), 3);
    }

}
